PostmarketOS 设备移植
介绍
主要步骤:
- 设置 postmarketOS 开发环境
- 构建设备专属内核,以及设备专属的系统包,或者使用主线内核和设备专属的系统包
- 安装系统,根据设备和使用方式进行定制
确定芯片型号
首先需要确定芯片(SoC)的型号。PostmarketOS 目前有对以下型号的主线文档:
- Snapdragon 410/412 MSM8916/Snapdragon 615/616 MSM8939
- Snapdragon 820/821 MSM8996
- Snapdragon 845 SDM845
如果你的 SoC 不在这里面,它也可能有好的主线支持。可以在 SoC 社区里找找,或者在 IRC 里面问问。
如果你的设备使用主线 Linux 内核,最好是继续使用它。你将能实现更好的硬件支持(CPU、modem 等),同时也能使用最新的软件。在一些情况下,可能会更容易。然而,如果你的设备没有得到任何(接近)主线内核的良好支持,请继续阅读本指南。
准备工作
请使用一个备用设备来折腾 PostmarketOS。另外,也不能保证你的设备不会损坏。
在 Devices 页面中搜索你的设备,看有没有前人适配过这个机型,避免做重复工作。同时也在 Wiki 中搜索你的机型,并且检查已经存在的分支链接。如果你的目标设备是 x86-64 CPU,你可以直接使用 generic x64 UEFI device 移植。
如果遇到问题,加入 IRC 多问问。
需要
开发环境
搭建开发环境需要一个 GNU/Linux 系统,能够构建、运行 pmbootstrap。pmbootstrap 是 PostmarketOS 的安装和运行工具。
知识
建议你最起码知道什么是 Linux 发行版,以及如何构建软件,因为移植过程要稍微难一点,不仅是调用几个命令。
目标设备
如果你的目标设备是 ARM 处理器,它必须要有 floating-point unit (FPU)。如果设备是 ARMv7 以上的,都应该有 FPU。对于 ARMv6 的,只有一部分有 FPU。
大多数手机都有 FPU。2012 年之后的都有 FPU。
初始化
参照 Install pmbootstrap 安装 pmbootstrap。
pmbootstrap 是一个 Python 包,使用 pip 安装:pip install pmbootstrap
之后初始化 pmbootstrap:pmbootstrap init
[maxiee@maxiee-hpbook src]$ pmbootstrap init
[06:11:42] Location of the 'work' path. Multiple chroots (native, device arch, device rootfs) will be created in there.
[06:11:42] Work path [/home/maxiee/.local/var/pmbootstrap]:
[06:11:57] Setting up the native chroot and cloning the package build recipes (pmaports)...
[06:11:57] Clone git repository: https://gitlab.com/postmarketOS/pmaports.git
Cloning into '/home/maxiee/.local/var/pmbootstrap/cache_git/pmaports'...
问我 work path 放在哪里,我选用默认的。
[06:12:07] Choose the postmarketOS release channel.
[06:12:07] Available (5):
[06:12:07] * edge: Rolling release / Most devices / Occasional breakage: https://postmarketos.org/edge
[06:12:07] * v21.12: Latest release / Recommended for best stability
[06:12:07] * v21.06: Old release (unsupported)
[06:12:07] * v21.03: Old release (unsupported)
[06:12:07] * v20.05: Old release (unsupported)
[06:12:07] Channel [edge]:
之后问我选用什么通道?我先选个 Edge 感受下,这是滚动发布同步,相当于测试分支,支持的设备最多,但是稳定性也较低。 补充:在 Edge 通道下,qemu 进行 pmbootstrap install 一步就失败了,mkinitfs 版本出现了冲突,包都没打出来。切到 v21.12 就好了。
[06:14:28] Choose your target device vendor (either an existing one, or a new one for porting).
[06:14:28] Available vendors (69): acer, alcatel, amazon, apple, ark, arrow, asus, bq, cubietech, essential, fairphone, finepower, fly, goclever, google, gp, hisense, htc, huawei, infocus, jolla, klipad, kobo, lark, leeco, lenovo, lg, medion, meizu, microsoft, mobvoi, motorola, nextbit, nobby, nokia, nvidia, odroid, oneplus, oppo, ouya, pegatron, pine64, planet, purism, qemu, raspberry, samsung, semc, sharp, shift, sipeed, sony, sourceparts, surftab, t2m, tablet, teclast, tokio, tolino, trekstor, vernee, wexler, wiko, wileyfox, xiaomi, xunlong, yu, zte, zuk
[06:14:28] Vendor [qemu]:
问我目标设备的厂商。默认是 qemu,这里我有点犹豫,是用 qumu 先练练,还是直接拿真机,先 qemu 把。 这里可以输入不存在的厂商,pmbootstrap 会问你是不是新厂商,由此开启新设备适配的流程。
[06:16:39] Available codenames (2): aarch64, amd64
[06:16:39] Device codename [amd64]:
选择架构,既然都 qemu 了,那还是 amd64,性能会好一些。
[06:17:22] Which kernel do you want to use with your device?
[06:17:22] Available kernels (2):
[06:17:22] * lts: Alpine LTS kernel
[06:17:22] * virt: Alpine Virt kernel (minimal, no audio)
[06:17:22] Kernel [lts]:
接着又让我选内核,默认选项就可以。
[06:18:01] Username [user]:
Username 改成我的 id:maxiee。
[06:18:36] Available user interfaces (20):
[06:18:36] * none: Bare minimum OS image for testing and manual customization. The "console" UI should be selected if a graphical UI is not desired.
[06:18:36] * asteroid: (Wayland) Smartwatch UI from AsteroidOS
[06:18:36] * console: Console environment, with no graphical/touch UI
[06:18:36] * fbkeyboard: Plain framebuffer console with touchscreen keyboard support
[06:18:36] * framebufferphone: Minimalist framebuffer menu/keyboard UI accessible via touch/volume keys & compatible scripts
[06:18:36] * glacier: (Wayland) Open-source alternative to the SailfishOS UI
[06:18:36] * gnome: (Wayland) Gnome Shell
[06:18:36] * i3wm: (X11) Tiling WM (keyboard required)
[06:18:36] * kodi: (GBM) 10-foot UI useful on TV's
[06:18:36] * lxqt: (X11) Lightweight Qt Desktop Environment (stylus recommended)
[06:18:36] * mate: (X11) MATE Desktop Environment, fork of GNOME2 (stylus recommended)
[06:18:36] * phosh: (Wayland) Mobile UI developed for the Librem 5
[06:18:36] * plasma-bigscreen: (Wayland) 10-feet variant of Plasma, made for big screen TVs
[06:18:36] * plasma-desktop: (X11/Wayland) KDE Desktop Environment (works well with tablets)
[06:18:36] * plasma-mobile: (Wayland) Mobile variant of KDE Plasma (does not run without hardware acceleration)
[06:18:36] * shelli: Plain console with touchscreen gesture support
[06:18:36] * sway: (Wayland) Tiling WM, drop-in replacement for i3wm (DOES NOT RUN WITHOUT HW ACCELERATION!)
[06:18:36] * sxmo-de-dwm: Simple Mobile: Mobile environment based on SXMO and running on dwm
[06:18:36] * sxmo-de-sway: Simple Mobile: Mobile environment based on SXMO and running on sway
[06:18:36] * weston: (Wayland) Reference compositor (demo, not a phone interface)
[06:18:36] * xfce4: (X11) Lightweight desktop (stylus recommended)
[06:18:36] User interface [weston]:
我是 KDE 当,口水 plasma-mobile 很久了,必须是它。
后面还有好多好多小问题,都是一些 Linux 基本配置,这里不再赘述。
初始化完毕:
[06:21:23] Build outdated packages during 'pmbootstrap install'? (y/n) [y]:
[06:21:55] WARNING: The chroots and git repositories in the work dir do not get updated automatically.
[06:21:55] Run 'pmbootstrap status' once a day before working with pmbootstrap to make sure that everything is up-to-date.
[06:21:55] DONE!
刷机方法
取决于设备使用的刷机协议。大多数 Android 设备,采用 fastboot,有些三星手机使用 heimdall,Maemo/MeeGo-based Nokia 手机采用 0xffff。
如果你不知道是哪种,进入 bootloader,看屏幕上显示 "Fastboot mode" 还是 "Odin mode"。
怎么进 Fastboot?通常是同时按音量下+电源启动设备。
更多信息参见 Deviceinfo flash methods。
work path
接下来去创建的 work path 里看看,默认地址是 /home/maxiee/.local/var/pmbootstrap/cache_git/pmaports
device 目录
所有的设备都在 device 目录下,该目录又分为 4 个子目录:community、main、testing、unmaintained。
device-qemu-aarch64 位于 main 中。
device-qemu-aarch64
该目录下一共 4 个文件:APKBUILD、deviceinfo、mce-display-blanking.conf、weston.ini。
内核包
长期目标是所有的设备都采用主线内核,但是当移植新设备的时候,通常都没法一步到位。我们实际上会搭载一个 Linux 的 Fork 内核,该内核是已知能在该设备上运行的(能跑起 Android 的)。
如果你的设备没有一个已知的能工作的 Linux 内核 Fork(比如 iPhone 或者 Windows Phone),这里的文档就不适用了。
APKBUILD
APKBUILD 是一个用于构建包的脚本。有两个 APKBUILD 是需要进行编辑的:设备的,Linux 的。
举例,这两个文件分别位于:
$workdir/cache_git/pmaports/device/testing/device-wiki-example/APKBUILD
$workdir/cache_git/pmaports/device/testing/linux-wiki-example/APKBUILD
实例,在上面选得 qemu 中:
# 设备的
/home/maxiee/.local/var/pmbootstrap/cache_git/pmaports/device/main/device-qemu-amd64/
# Linux 的目录没有找见
看起来 device 目录和 linux 目录的命名格式是对齐的,也就是说应当还有一个 linux-qemu-amd64,难道说 qemu 的直接用主线,跟别的不一样?
Source code
这里说的源代码主要是可以工作的 Kernel Fork,参见 LineageOS 文档。如果可能的话,找那些广泛使用的,比如 LineageOS。内核版本也很重要。
有了内核之后,调整 linux 目录的 linux-wiki-example/APKBUILD 文件。对于 LineageOS 内核来说,只需要更改 _repository 和 _commit 变量。
如果你的内核不来自 LineageOS,可以修改 source 到 URL,比如 https://github.com/jmrohwer/$_repository/archive/$_commit.tar.gz,如果来自 GitHub 仓库,还是要设置 _repository 和 _commit 变量。
如果内核来自一个压缩包(zip, tarball),首先需要解压,然后通过下面命令进行本地添加:pmbootstrap build linux-wiki-example --src=/path/to/extracted/kernel/source。
将内核提交到 PostmarketOS 上游
内核适配的工作,后续可以贡献到 PostmarketOS 的官方源中,这样所有人都能够复用。
在贡献之前,talk to us 先参见这个文档。
下载内核源码
pmbootstrap checksum linux-wiki-example
安装
前面配置完成之后,接下来是通过 install 命令进行安装:
[maxiee@maxiee-hpbook src]$ pmbootstrap install
[06:58:42] *** (1/4) PREPARE NATIVE CHROOT ***
[06:58:44] *** (2/4) CREATE DEVICE ROOTFS ("qemu-amd64") ***
[06:58:46] (rootfs_qemu-amd64) install postmarketos-base device-qemu-amd64 postmarketos-ui-plasma-mobile device-qemu-amd64-kernel-lts postmarketos-ui-plasma-mobile-extras angelfish breeze-gtk discover firefox-esr font-noto font-noto-emoji index kaccounts-providers kclock kde-gtk-config kirigami-gallery koko kpeoplesink kpeoplevcard megapixels mobile-config-firefox plasma-dialer plasma-mobile-sounds plasma-phonebook postmarketos-artwork-wallpapers postmarketos-hidden-desktop-entries qmlkonsole spacebar ttf-droid-nonlatin ttyescape xdg-user-dirs alligator buho calindori elisa kaidan kalk kasts kdeconnect keysmith kongress krecorder ktrip kweather neochat nota okular-mobile tokodon vvave lang musl-locales postmarketos-base-nofde
报错 Command failed (exit code 10): apk add -u --virtual
完整报错:
[06:58:46] NOTE: The failed command's output is above the ^^^ line in the log file: /home/maxiee/.local/var/pmbootstrap/log.txt
[06:58:46] ERROR: Command failed (exit code 10): apk add -u --virtual .pmbootstrap postmarketos-base device-qemu-amd64 postmarketos-ui-plasma-mobile device-qemu-amd64-kernel-lts postmarketos-ui-plasma-mobile-extras angelfish breeze-gtk discover firefox-esr font-noto font-noto-emoji index kaccounts-providers kclock kde-gtk-config kirigami-gallery koko kpeoplesink kpeoplevcard megapixels mobile-config-firefox plasma-dialer plasma-mobile-sounds plasma-phonebook postmarketos-artwork-wallpapers postmarketos-hidden-desktop-entries ……
[06:58:46] See also: <https://postmarketos.org/troubleshooting>
Run 'pmbootstrap log' for details.
通过 pmbootstrap log 查看日志,发现是有包冲突了:
WARNING: Ignoring /mnt/pmbootstrap-packages: No such file or directory
ERROR: unable to select packages:
postmarketos-mkinitfs-1.4.1-r1:
breaks: linux-lts-5.15.36-r1[mkinitfs>=3.6.0]
satisfies: postmarketos-base-20-r0[postmarketos-mkinitfs]
postmarketos-base-nofde-20-r0[postmarketos-mkinitfs]
.pmbootstrap-20220429.230259[postmarketos-mkinitfs]
.pmbootstrap-20220429.230259[mkinitfs]
.pmbootstrap-20220429.230259:
masked in: cache
satisfies: world[.pmbootstrap=20220429.230259]
postmarketos-mkinitfs 包:Tool to generate initramfs images for postmarketOS。它提供的 mkinitfs=0.0.1。
而 Linux 内核需要的 mkinitfs 要大于 3.6.0(怎么差这么多)。
将通道从 Edge 切到 v21.12 就好了,暂且跑通,以后再研究下是怎么回事。
网络资源
Install And Configure PostmarketOS With Plasma Mobile On The PinePhone
给红米Note3高配版手机刷入Linux系统postmarketOS
PostmarketOS Pmbootstrap Notes
nexus-5-upstream:研究地很深入。